const { sequelize } = require("../../core/db");
const { Sequelize, Model } = require("sequelize");

class Refund extends Model {}

Refund.init(
  {
    refund_id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    out_refund_no: {
      type: Sequelize.STRING,
      allowNull: false,
      defaultValue: () => {
        return "ORN" + Date.now() + "" + Math.floor(Math.random() * 10000);
      },
      comment: "商户退款单号",
    },
    out_trade_no: {
      type: Sequelize.STRING,

      comment: "商户订单号",
    },
    transaction_id: {
      type: Sequelize.STRING,

      comment: "微信订单号",
    },
    reason: {
      type: Sequelize.STRING,
      allowNull: false,
      comment: "退款原因",
    },
    funds_account: {
      type: Sequelize.STRING,

      comment: "退款资金来源",
    },
    refund: {
      type: Sequelize.STRING,

      comment: "退款金额",
    },
    total: {
      type: Sequelize.STRING,

      comment: "订单金额",
    },
    currency: {
      type: Sequelize.STRING,

      defaultValue: "CNY",
      comment: "货币类型",
    },
    refund_status: {
      type: Sequelize.INTEGER,
      allowNull: false,
      defaultValue: 0, //-1 退款关闭 0 退款处理中 1 退款成功，2 退款异常
      comment: "退款状态",
    },
    goods_detail: {
      type: Sequelize.STRING,

      comment: "商品详情",
    },
  },
  {
    sequelize,
    tableName: "refund",
  }
);

module.exports = {
  Refund,
};
